home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0045_More File Handles.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  2KB  |  72 lines

  1. {
  2. From: BRIAN GRAINGER               Refer#: NONE
  3. Subj: Multiple open files            Conf: (58) Pascal
  4. ---------------------------------------------------------------------------
  5. RL▒I would like to open 20-50 silumtaneous files (in TP 6.0 or 7.0).
  6.  
  7. Two ways that I know of. The first involves sleuthing around in the
  8. Program Segment Prefix prepended to the memory image of a program's .EXE
  9. file. This involves undocumented DOS calls, but is known to work.
  10.  
  11. The second is to use Interrupt 21h, Function 67h, Set Handle Count.
  12. This is buggy in the original release of DOS 3.3, but is apparently
  13. reliable in later versions.
  14. }
  15.  
  16. USES
  17.   Dos;
  18.  
  19. CONST
  20.   LotsaHandles = 24861;
  21.  
  22. FUNCTION SetHandleCount(Count : WORD) : WORD;
  23.   VAR
  24.     Regs : Registers;
  25.   BEGIN
  26.     SetHandleCount := 0;
  27.     WITH Regs DO
  28.       BEGIN
  29.         AH := $67;
  30.         BX := Count;
  31.         Intr($21, Regs);
  32.         IF Flags AND fCarry <> 0 THEN (* Error?                *)
  33.           SetHandleCount := AX;       (* AX returns error code *)
  34.       END;
  35.   END;
  36.  
  37. BEGIN
  38.   IF SetHandleCount(LotsaHandles) <> 0 THEN
  39.     WriteLn('Sorry. Better luck next time.')
  40.   ELSE
  41.     WriteLn('What do think I am, a mainframe?');
  42. END.
  43.  
  44. { ASSEMBLER TO DO THE SAME THING
  45.  
  46. (If you are not using protected mode you have to limit the use of DOS memory
  47. by using compiler direvtive $M in BP. DOS steals the first 5 handles for std.
  48. devices. This require at least DOS 3.3)
  49. }
  50.  
  51.  
  52. procedure SetHandleCount( wInAnt: WORD );
  53. var
  54.  err            : Boolean;
  55. begin
  56. asm
  57.  
  58.         MOV     AX, $6700;
  59.         MOV     BX, wInAnt
  60.         INT     $21
  61.         MOV     err, 0
  62.         JNC     @l1
  63.         MOV     err, 1          { Error! }
  64. @l1:
  65. end;
  66.   if err then begin
  67.     ClrScr;
  68.     writeln('Not enough memory');
  69.     halt(0);
  70.   end;
  71. end;
  72.